import 'dart:convert';

import 'package:equatable/equatable.dart';

import '../socket/dto/business/Message.dart';
import '../socket/dto/business/PullData.dart';
import '../util/DateUtil.dart';
import '../util/FileUtil.dart';
import 'Enums.dart';

class ImDepartment extends Equatable {
  final int? id;
  final String currentUserId;
  final String code;
  final String? name;
  final String? description;
  final String? parentCode;
  final String? managerUserId;
  final Set<String>? otherManagerUserIdSet;
  final String? otherManagerUserIds;
  ImDepartmentStatus? status;
  final String? ext1;
  final String? ext2;
  DateTime? createTime;
  DateTime? updateTime;

  List<ImDepartment> children = <ImDepartment>[];

  ImDepartment({
    this.id,
    required this.currentUserId,
    required this.code,
    this.name,
    this.description,
    this.parentCode,
    this.managerUserId,
    this.otherManagerUserIdSet,
    this.otherManagerUserIds,
    this.status  = ImDepartmentStatus.enable,
    this.ext1,
    this.ext2
  }): this.createTime = DateTime.now(), this.updateTime = DateTime.now();

  @override
  List<Object?> get props => [id];
}

class ImUser extends Equatable {
  int? id;
  String userId;
  String? userName;
  String? mobile;
  String? motto;   // 格言
  String? headImg;
  String? description;  // 自我介绍
  String? departmentCode;
  String? otherDepartmentCodes;
  ImUserStatus? status;
  SexEnum? sex;
  String? ext1;
  String? ext2;
  String? firstLetter;
  DateTime? createTime;
  DateTime? updateTime;

  ImUser(this.userId) : this.createTime = DateTime.now(),
    this.updateTime = DateTime.now(),
    this.status = ImUserStatus.enable;

  @override
  List<Object?> get props => [userId];
}

class ImGroup {
  int? id;
  String? currentUserId;
  String code;
  String? name;
  String? ownerId;   // 群主
  String? description;
  int? version;
  ImGroupType? groupType;
  ImGroupStatus? status;
  String? ext1;
  String? ext2;
  String? firstLetter;
  DateTime createTime;
  DateTime updateTime;

  String? userName;
  ImUser? imUser;
  ImGroupUser? currentGroupUser;
  Set<ImGroupUser>? groupUserList;

  ImGroup({this.id, this.currentUserId, required this.code, this.name, this.ownerId,
    this.description, this.version, this.groupType, this.status, this.ext1, this.ext2
  }): this.createTime = DateTime.now(),
      this.updateTime = DateTime.now()
  ;

  @override
  int get hashCode => code.hashCode;

  @override
  operator == (Object other) => other is ImGroup ? code == other.code : false;

}

class ImGroupUser {
  int? id;
  int? groupId;
  String userId;
  String? userName;
  String? remark;
  bool isWaking;                 // 是否提醒
  bool isShowName;               // 是否显示用户名称
  bool isTop;                    // 是否置顶
  bool isDisturb;                // 是否免打扰
  String? ext1;
  String? ext2;
  ImGroupUserStatus status;
  DateTime? createTime;
  DateTime? updateTime;

  ImUser? user;

  ImGroupUser(this.userId):this.isWaking = false,
    this.isShowName = true,
    this.isTop = false,
    this.isDisturb = false,
    this.status = ImGroupUserStatus.enable,
    this.createTime = DateTime.now(),
    this.updateTime = DateTime.now()
  ;

  @override
  int get hashCode => id != null ? id.hashCode : groupId.hashCode * 17 + userId.hashCode;

  @override
  operator == (Object other) => other is ImGroupUser ? (id != null ? other.id == id : other.userId == userId && other
      .groupId == groupId)
      : false;

  @override
  String toString() {
    return "id: $id, groupId: $groupId, userId: $userId, userName: $userName, isWaking: $isWaking, "
        "isTop: $isTop, isDisturb: $isDisturb, user: $user";
  }
}

class ImSession extends Equatable {

  int? id;
  String? currentUserId;
  String? name;
  String? fromUserId;
  String? toUserId;
  String? serverId;
  String? groupCode;
  int? hotMessageTotal;
  String? latelyMessage;
  ImSessionType? sessionType;
  ImSessionStatus? status;
  bool isWaking;
  bool isWaking2;
  bool isTop;
  bool isDisturb;
  bool isTop2;
  bool isDisturb2;
  String? ext1;
  String? ext2;
  DateTime createTime;
  DateTime updateTime;

  ImUser? toUser;
  ImGroup? group;
  List<ImGroupUser>? groupUsers;

  ImSession() :
    this.isWaking = false,
    this.isWaking2 = false,
    this.isTop = false,
    this.isDisturb = true,
    this.isTop2 = false,
    this.isDisturb2 = true,
    this.createTime = DateTime.now(),
    this.updateTime = DateTime.now();

  static ImSession buildWithUser(String userId, ImUser? toImUser) {
    var imSession = ImSession();
    imSession.sessionType = ImSessionType.chat;
    imSession.status = ImSessionStatus.created;
    imSession.fromUserId = userId;
    imSession.currentUserId = userId;
    imSession.toUser = toImUser;
    if (toImUser != null) {
      imSession.toUserId = toImUser.userId;
      imSession.name = toImUser.userName;
    }
    imSession.latelyMessage = '';
    imSession.hotMessageTotal = 0;
    return imSession;
  }

  static ImSession buildWithGroup(String userId, ImGroup group) {
    var imSession = ImSession.buildWithUser(userId, null);
    imSession.group = group;
    if (group != null) {
      imSession.groupCode = group.code;
      imSession.name = group.name;
    }
    if (imSession.serverId != null) {
      imSession.status = ImSessionStatus.enable;
    }
    return imSession;
  }

  // @override
  // bool operator == (Object other) {
  //   if (!(other is ImSession)) return false;
  //   ImSession imSession = other as ImSession;
  //   return imSession.id == id;
  // }
  //
  // @override
  // int get hashCode {
  //   return this.id.hashCode;
  // }

  @override
  List<Object?> get props => [id, name, latelyMessage, hotMessageTotal, group, groupUsers];
}

class ImMessage {
  int? id;
  String? clientId;
  String fromUserId;
  String? toUserId;
  String currentUserId;
  String? serverId;
  ImMessageType messageType;
  String? groupCode;
  String content;
  int? sessionId;
  ImMessageRefType? refType;
  String? refMessageIds;
  String? ext;
  String? ext1;
  String? ext2;
  int? version;
  ImMessageStatus? status;
  ImMessageFileStatus? fileStatus;  // 附件的状态
  ImMessageActionStatus? actionStatus;
  DateTime? serverReceiveTime;
  DateTime createTime;
  DateTime updateTime;

  MessageExt? messageExt;
  ImUser? fromImUser;
  ImGroupUser? fromGroupUser;
  ImUser? toImUser;
  ImSession? imSession;
  Set<ImMessageSend>? messageSendSet;
  List<ImMessage>? refMessages;

  ImMessage({required this.fromUserId, required this.messageType, required this.content}) :
    this.currentUserId = fromUserId,
    this.version = 1,
    this.status = ImMessageStatus.none,
    this.actionStatus = ImMessageActionStatus.none,
    this.serverReceiveTime = DateTime.now(),
    createTime = DateTime.now(),
    updateTime = DateTime.now()
  ;

  bool get isGroup {
    return groupCode != null;
  }

  bool isSender(String userId) {
    return fromUserId == userId;
  }

  bool isReceiver(String userId) {
    return !isSender(userId);
  }

  MessageExt? initMessageExt() {
    if (ext != null && ext!.trim() != '') {
      messageExt = MessageExt.fromJson(jsonDecode(ext!));
    }
    return messageExt;
  }

  void init() {
    if (messageExt != null) {
      ext = jsonEncode(messageExt);
    }
  }

  @override
  int get hashCode => id != null ? id.hashCode : (serverId != null ? serverId.hashCode : clientId.hashCode);

  @override
  operator == (Object other) => other is ImMessage ? (id == other.id || serverId == other.serverId
      || clientId == other.clientId) : false;

  bool isAttachFile() {
    return this.messageType == ImMessageType.Image
        || this.messageType == ImMessageType.File
        || this.messageType == ImMessageType.Audio;
  }

  // @override
  // List<Object?> get props => [id, actionStatus, updateTime];
}

class ImMessageSend {
  int? id;
  int? messageId;
  String userId;
  ImMessageStatus status;
  ImMessageFileStatus? fileStatus;        // 附件的状态
  ImMessageActionStatus? actionStatus;
  DateTime createTime;
  DateTime updateTime;

  ImMessageSend({required this.userId, required this.status}) :
      this.createTime = DateTime.now(),
      this.updateTime = DateTime.now();
}

class MessageExt {
  bool remote;      // 否：本地上传的文件。 是： 远程下载的文件
  String fileUrl;
  String fileName;
  String md5;
  String originalName; // 原始文件名称
  int size;
  int? time;
  int? imageWidth;
  int? imageHeight;

  MessageExt({required this.remote, required this.fileName, required this.md5, required this.fileUrl,
    required this.originalName, required this.size, this.time, this.imageWidth, this.imageHeight});

  factory MessageExt.fromJson(Map<String, dynamic> map) =>_MessageExtFromJson(map);

  Map<String, dynamic> toJson() => _MessageExtToJson(this);
}

MessageExt _MessageExtFromJson(Map<String, dynamic> json) =>
    MessageExt(
      remote: (json['remote'] ?? false) as bool,
      fileUrl: json['fileUrl'] as String,
      fileName: json['fileName'] as String,
      md5: json['md5'] as String,
      originalName: json['originalName'] as String,
      size: json['size'] as int,
      time: json['time'] as int?,
    )..imageWidth = json['imageWidth'] as int?
      ..imageHeight = json['imageHeight'] as int?;

Map<String, dynamic> _MessageExtToJson(MessageExt instance) =>
    <String, dynamic>{
      'remote': instance.remote,
      'fileUrl': instance.fileUrl,
      'fileName': instance.fileName,
      'md5': instance.md5,
      'originalName': instance.originalName,
      'size': instance.size,
      'time': instance.time,
      'imageWidth': instance.imageWidth,
      'imageHeight': instance.imageHeight,
    };

class ImSensitiveWord {
  int? id;
  String word;
  ImSensitiveWordStatus status;
  DateTime createTime;
  DateTime updateTime;

  ImSensitiveWord({required this.word, this.id}) :
    this.status = ImSensitiveWordStatus.enable,
    this.createTime = DateTime.now(),
    this.updateTime = DateTime.now();

}

class ImSetting {
  int? id;
  String name;
  String currentUserId;
  String? description;
  String? value;
  String? ext1;
  String? ext2;
  DateTime? createTime;
  DateTime? updateTime;

  ImSetting({this.id, required this.name, required this.currentUserId, this.description, this.value, this.ext1,
    this.ext2}):
      this.createTime = DateTime.now(),
      this.updateTime = DateTime.now();
}

class ImLogin {
  int? id;
  String userId;
  String? token;
  LoginType loginType;
  String? maskPassword;
  DateTime updateTime;

  ImLogin({this.id, required this.userId, this.token, this.maskPassword, required this.loginType})
      :  this.updateTime = DateTime.now();
}

class ImConfig {
  int? id;
  String currentUserId;
  String name;
  String content;
  ImConfigStatus status;
  DateTime createTime;
  DateTime updateTime;

  ImConfig({this.id, required this.currentUserId, required this.name, required this.content, required this.status})
      :  this.updateTime = DateTime.now(),
         this.createTime = DateTime.now();
}

class ImModule extends Equatable {
  int? id;
  String name;
  String? description;
  ImModuleStatus status;
  int no;
  DateTime createTime;
  DateTime updateTime;

  List<ImModuleItem>? moduleItemList;

  ImModule({this.id, required this.name, this.description, required this.status, required this.no})
      :  this.updateTime = DateTime.now(),
        this.createTime = DateTime.now();

  @override
  List<Object?> get props => [name, status, no, moduleItemList];
}

class ImModuleItem extends Equatable {
  int? id;
  int? moduleId;
  String name;
  String? description;
  String icon;
  String? url;
  String? params;
  ImModuleItemType type;
  ImModuleItemStatus status;
  int no;
  DateTime createTime;
  DateTime updateTime;

  ImModuleItem({this.id, this.moduleId, required this.name, this.description, required this.status,
    required this.no, required this.icon, this.url, this.params, required this.type})
      :  updateTime = DateTime.now(),
         createTime = DateTime.now();

  @override
  List<Object?> get props => [name, icon, url, params, type, status, no];
}

class ImCollect extends Equatable{
  int? id;
  String userId;
  String? serverId;
  String messageId;
  String sessionId;
  String content;
  String? labelIds;
  ImMessageType messageType;
  ImCollectStatus status;
  DateTime createTime;
  DateTime updateTime;

  ImCollectContent? collectContent;
  ImMessage? message;

  ImCollect({this.id, required this.userId, this.serverId, required this.messageId, required this.sessionId,
    required this.content, this.labelIds, required this.messageType, required this.status})
      :  updateTime = DateTime.now(),
         createTime = DateTime.now();

  ImCollectContent? getCollectContent() {
    if (content != null && collectContent == null) {
      collectContent = ImCollectContent.fromJson(jsonDecode(content));
    }
    return collectContent;
  }

  initContent() {
    if (collectContent == null) {
      collectContent = ImCollectContent.fromJson(jsonDecode(content));
      message = toMessage(collectContent!);
    }
  }

  ImMessage toMessage(ImCollectContent collectContent) {
    var message = ImMessage(fromUserId: collectContent.fromUserId, messageType: messageType, content: collectContent.content);
    message.serverId = collectContent.messageId;
    message.toUserId = collectContent.toUserId;
    message.groupCode = collectContent.groupCode;
    message.ext = collectContent.fileContent;
    message.fileStatus = ImMessageFileStatus.downloaded;
    return message;
  }

  @override
  List<Object?> get props => [id];
}

class ImCollectContent {

  String content;
  String? fileContent;
  String fromUserId;
  String? toUserId;
  String? groupCode;
  DateTime? messageTime;
  ImMessageType messageType;
  String messageId;

  List<ImCollectContent>? refCollectContents; // 关联消息内容

  ImCollectContent({required this.content, required this.fromUserId, required this.messageId,
    required this.messageType});

  ImMessage toMessage() {
    ImMessage message = ImMessage(fromUserId: fromUserId, messageType: messageType, content: content);
    message.serverId = messageId;
    message.toUserId = toUserId;
    message.groupCode = groupCode;
    message.ext = fileContent;
    message.fileStatus = ImMessageFileStatus.downloaded;
    return message;
  }

  factory ImCollectContent.fromJson(Map<String, dynamic> map) =>
      ImCollectContent(fromUserId: map['fromUserId'] as String,
        messageId: map['messageId'] as String,
        content: map['content'] as String,
        messageType: ImMessageType.ofName(map['messageType'])
      )..groupCode = map['groupCode'] as String?
       ..toUserId = map['toUserId'] as String?
       ..fileContent = map['fileContent'] as String?
       .. messageTime = map['messageTime'] == null
           ? null
           : DateTime.parse(map['messageTime'] as String)
    ;

  Map<String, dynamic> toJson() => {
    'fromUserId': fromUserId,
    'content': content,
    'fileContent': fileContent??'',
    'toUserId': toUserId,
    'groupCode': groupCode,
    'messageType': messageType.name,
    'messageId': messageId,
    'messageTime': DateUtil.formatDate(messageTime),
  };

  @override
  String toString() {
    return jsonEncode(this);
  }
}

class ImFile {
  int? id;
  String currentUserId;
  String sessionId;
  String messageId;
  String fileName;
  String md5;
  int fileSize;
  String path;
  bool isRelativePath;  // 上传时，绝对路径。其它时是相对路径
  String suffix;
  ImFileStatus status;
  DateTime createTime;
  DateTime updateTime;

  ImSession? session;

  ImFile({ required this.currentUserId, required this.sessionId, required this.messageId, required this.fileName,
    required this.md5, required this.fileSize, required this.path, required this.isRelativePath}) :
      status = ImFileStatus.enable,
      createTime = DateTime.now(),
      updateTime = DateTime.now(),
      suffix = FileUtil.getSuffix(fileName)
  ;

  @override
  int get hashCode => id != null ? id.hashCode : Object.hash(sessionId, messageId);

  @override
  operator == (Object other) => other is ImFile ? (id == other.id || (sessionId == other.sessionId
      && messageId == other.messageId)) : false;

}

class ImHotMessageTotal {
  int sessionId;
  int total;

  ImHotMessageTotal({ required this.sessionId, required this.total});
}

enum ImUserStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImUserStatus(this.value, this.desc);

  static ImUserStatus ofName(String? name) {
    ImUserStatus? result = ImUserStatus.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImUserStatus ofValue(int? value) {
    ImUserStatus? result = ImUserStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImMessageType {
  Text,
  Image,
  Web,
  File,
  Html,
  Video,
  RichText,
  Audio,
  Url,
  Chat,
  Group;

  static ImMessageType ofName(String name) {
    ImMessageType? result = ImMessageType.values.firstWhere((e) => e.name == name);
    return result;
  }

  bool isFile() {
    return this == Image || this == Audio || this == File || this == Video;
  }

  bool isText() {
    return this == Text || this == Web || this == Html || this == RichText || this == Url;
  }
}

enum ImMessageRefType {
  ref(1, "引用"),
  transfer(2, "转发"),
  ;

  final int value;
  final String desc;

  const ImMessageRefType(this.value, this.desc);

  static ImMessageRefType? ofValue(int? value) {
    if(value == null) return null;
    ImMessageRefType? result = ImMessageRefType.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImMessageStatus {
  none(0, "空"),
  created(1, "已创建"), // 已经创建
  sended(3, "已发送"),
  readed(5, "已阅读"),
  delete(9, "删除"),
  withdraw(11, "撤回"), // 被取消
  withdrawed(12, "已撤回"),
  updated(20, "已更新"), // 失败
  disable(30, "不可用"), // 消息在接受中， 发送文件，图片等才有这种状态
  serverDeleted(50, "已删除"), // 接受成功
  ref(60, "引用消息"), // 删除
  failure(-100, "失败"),
  sending(-10, "发送中"),
  ;

  final int value;
  final String desc;

  const ImMessageStatus(this.value, this.desc);

  static ImMessageStatus ofValue(int? value) {
    ImMessageStatus? result = ImMessageStatus.values.firstWhere((e) => e.value == value);
    return result;
  }

  static ImMessageStatus ofName(String? name) {
    ImMessageStatus? result = ImMessageStatus.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImMessageStatus wrap(MessageStatus? messageStatus) {
    if (messageStatus == MessageStatus.receive) {
      return ImMessageStatus.sended;
    } else if (messageStatus == MessageStatus.readed) {
      return ImMessageStatus.sended;
    } else if (messageStatus == MessageStatus.withdrawed) {
      return ImMessageStatus.withdrawed;
    } else if (messageStatus == MessageStatus.delete) {
      return ImMessageStatus.serverDeleted;
    } else if (messageStatus == MessageStatus.updated) {
      return ImMessageStatus.updated;
    } else if (messageStatus == MessageStatus.none) {
      return ImMessageStatus.created;
    }
    throw Exception("ImMessageStatus不支持这种类型: ${messageStatus?.name}");
  }

  bool isWithdraw() {
    return this == ImMessageStatus.withdraw || this == ImMessageStatus.withdrawed;
  }
}

enum ImMessageActionStatus {
  // 发送端和接受端
  none(0, "空"),                  // 未知
  // 发送端
  withdraw(6, "撤回"),            // 撤回
  withdrawed(7, "已撤回"),        // 撤回并同步到服务器

  delete(9, '删除'),              // 用户删除
  deleted(10, "已删除"),          // 用户删除并同步到服务器

  // 接收端
  read(1, "读"),                 // 已阅读，需要同步到服务器端
  readed(2, "已读"),             // 已读并同步到服务器
  ;

  final int value;
  final String desc;

  const ImMessageActionStatus(this.value, this.desc);

  static ImMessageActionStatus? ofValue(int? value) {
    if (value == null) return null;
    ImMessageActionStatus? result = ImMessageActionStatus.values.firstWhere((e) => e.value == value);
    return result;
  }

  static ImMessageActionStatus? wrap(MessageActionStatus? messageActionStatus, bool isSender) {
    if (messageActionStatus == null) {
      return null;
    } else if (messageActionStatus == MessageActionStatus.none) {
      return ImMessageActionStatus.none;
    } else if (messageActionStatus == MessageActionStatus.readed) {
      return ImMessageActionStatus.readed;
    } else if (messageActionStatus == MessageActionStatus.withdrawed) {
      return ImMessageActionStatus.withdrawed;
    } else if (messageActionStatus == MessageActionStatus.userDelete) {
      return ImMessageActionStatus.deleted;
    }
    throw new Exception("不支持这种类型: ${messageActionStatus?.name}");
  }

  bool isWithdraw() {
    return this == ImMessageActionStatus.withdraw || this == ImMessageActionStatus.withdrawed;
  }
}

enum ImMessageFileStatus {
  empty(-1, ""),              // 接收端使用：文件上传中
  none(0, "空"),              // 接收端使用：文件已经上传，可以下载
  created(1, "已创建"),        // 已经创建
  uploading(2, "上传中"),      // 上传中
  uploaded(3, "已上传"),       // 发送到服务器，并返回成功
  downloaded(4, "已下载"),     // 已下载
  downloading(5, "下载中"),    // 下载中
  download_fail(6, "下载失败"),// 下载失败
  upload_fail(7, "上传失败"),  // 上传失败
  ;

  final int value;
  final String desc;

  const ImMessageFileStatus(this.value, this.desc);

  static ImMessageFileStatus? ofValue(int? value) {
    if (value == null) return null;
    ImMessageFileStatus? result = ImMessageFileStatus.values.firstWhere((e) => e.value == value);
    return result;
  }

  static ImMessageFileStatus? ofName(String? name) {
    ImMessageFileStatus? result = ImMessageFileStatus.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImMessageFileStatus? wrap(MessageFileStatus? fileStatus, bool isSender) {
    if (fileStatus == null) return ImMessageFileStatus.empty;
    if (fileStatus == MessageFileStatus.none) {
      return ImMessageFileStatus.none;
    } else if (fileStatus == MessageFileStatus.uploaded) {
      return isSender ? ImMessageFileStatus.downloaded : ImMessageFileStatus.uploaded;
    } else if (fileStatus == MessageFileStatus.downloading) {
      return isSender ? ImMessageFileStatus.downloaded :ImMessageFileStatus.uploaded;
    } else if (fileStatus == MessageFileStatus.downloaded) {
      return isSender ? ImMessageFileStatus.downloaded : ImMessageFileStatus.uploaded;
    }
    throw Exception("ImMessageFileStatus不支持这种类型MessageFileStatus( ${fileStatus?.name})");
  }
}

enum ImDepartmentStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImDepartmentStatus(this.value, this.desc);

  static ImDepartmentStatus ofValue(int? value) {
    ImDepartmentStatus? result = ImDepartmentStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImGroupType {
  chat(1, 'chat'),
  ;
  final int value;
  final String desc;

  const ImGroupType(this.value, this.desc);

  static ImGroupType ofName(String? name) {
    ImGroupType? result = ImGroupType.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImGroupType ofValue(int? value) {
    ImGroupType? result = ImGroupType.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImGroupStatus {
  none(-1, "空"),
  enable(1, "有效"),
  disable(2, "无效"),
  dissolution(3, "解散"),
  prohibition(4, "禁言"),
  ;

  final int value;
  final String desc;

  const ImGroupStatus(this.value, this.desc);

  static ImGroupStatus ofName(String? name) {
    ImGroupStatus? result = ImGroupStatus.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImGroupStatus ofValue(int? value) {
    ImGroupStatus? result = ImGroupStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImGroupUserStatus {
  enable(1, "有效"),
  disable(2, "无效"),
  dissolution(3, "解散"),
  prohibition(4, "禁言"),
  ;

  final int value;
  final String desc;

  const ImGroupUserStatus(this.value, this.desc);

  static ImGroupUserStatus ofName(String? name) {
    ImGroupUserStatus? result = ImGroupUserStatus.values.firstWhere((e) => e.name == name);
    return result;
  }

  static ImGroupUserStatus ofValue(int? value) {
    ImGroupUserStatus? result = ImGroupUserStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImSessionStatus {
  created(0, "刚创建"),  // 刚创建
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImSessionStatus(this.value, this.desc);

  static ImSessionStatus? ofValue(int? value) {
    if (value == null) return null;
    ImSessionStatus? result = ImSessionStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImSessionType {
  chat(1, "聊天"),
  ;

  final int value;
  final String desc;

  const ImSessionType(this.value, this.desc);

  static ImSessionType ofValue(int? value) {
    ImSessionType? result = ImSessionType.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImSensitiveWordStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImSensitiveWordStatus(this.value, this.desc);

  static ImSensitiveWordStatus ofValue(int? value) {
    ImSensitiveWordStatus? result = ImSensitiveWordStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImConfigStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImConfigStatus(this.value, this.desc);

  static ImConfigStatus ofValue(int? value) {
    ImConfigStatus? result = ImConfigStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImModuleStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImModuleStatus(this.value, this.desc);

  static ImModuleStatus ofValue(int? value) {
    ImModuleStatus? result = ImModuleStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImModuleItemStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImModuleItemStatus(this.value, this.desc);

  static ImModuleItemStatus ofValue(int? value) {
    ImModuleItemStatus? result = ImModuleItemStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImModuleItemType {
  page(1, "html页面"),
  origin(2, "原生"),
  ;

  final int value;
  final String desc;

  const ImModuleItemType(this.value, this.desc);

  static ImModuleItemType ofValue(int? value) {
    ImModuleItemType? result = ImModuleItemType.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImCollectStatus {
  enable(1, "可用"),
  disable(2, "不可用"),
  ;

  final int value;
  final String desc;

  const ImCollectStatus(this.value, this.desc);

  static ImCollectStatus ofValue(int? value) {
    ImCollectStatus? result = ImCollectStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}

enum ImFileStatus {
  enable(1, "可用"),
  delete(0, "删除"),
  deleted(3, "已删除"),
  ;

  final int value;
  final String desc;

  const ImFileStatus(this.value, this.desc);

  static ImFileStatus ofValue(int? value) {
    ImFileStatus? result = ImFileStatus.values.firstWhere((e) => e.value == value);
    return result;
  }
}